//
//  DWCustomPlayerView.m
//  xpkc
//
//  Created by TopSageOSX on 14-8-19.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "DWCustomPlayerView.h"

@implementation DWCustomPlayerView{
    BOOL outflag;
    UIButton * _currentBtn;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self creatPlayerView];
    }
    return self;
}
/**
 *  创建视图
 */
-(void)creatPlayerView{
    
    /**
     *  创建控件
     */
    self.questionView = [[UIView alloc]init];
    self.topView = [[UIView alloc]init];
    self.bottomView = [[UIView alloc]init];
    self.mainView = [[UIView alloc]init];
    self.gestureView = [[UIView alloc]init];
    //提问问题
    self.closeBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    self.finishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //顶部视图的控件
    self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.videoTitle = [[UILabel alloc]init];
    self.mulu = [[UILabel alloc]init];
    self.shu = [[UILabel alloc]init];
    
    self.questionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.qualityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //底部视图的控件
    self.progressSlider = [[UISlider alloc]init];
    
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.passBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.currentProgressTime = [[UILabel alloc]init];
    self.videoTotalTime = [[UILabel alloc]init];
    
    //    self.favoriteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.videoRate = [UIButton buttonWithType:UIButtonTypeCustom];
    self.videoRateBg = [UIButton buttonWithType:UIButtonTypeCustom];
    //    self.rateView = [[UIView alloc]init];
    
    
    self.rateView.backgroundColor = [UIColor redColor];
    //其他
    //    self.qualityView = [[UIView alloc]init];
    self.downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.subtitleLabel = [[UILabel alloc]init];
    self.noteLabel = [[UILabel alloc]init];
    self.volume = [[UIImageView alloc]init];
    self.schedule = [[UIImageView alloc]init];
    self.volumeSlider = [[UISlider alloc]init];
    self.volumeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIView *volumeView = [[UIView alloc]init];
    
    /**
     *  设置位置
     */
    CGRect question_view_frame;
    CGRect top_view_frame,bottom_view_frame,main_view_frame;
    CGRect back_frame;
    CGRect close_frame;
    CGRect finish_frame;
    CGRect title_frame;
    CGRect mulu_frame;
    CGRect shu_frame;
    CGRect question_btn_frame;
    CGRect quality_btn_frame;
    CGRect quality_view_frame;
    CGRect play_btn_frame;
    CGRect pass_btn_frame;
    CGRect next_ntm_frame;
    CGRect progress_slider_frame,current_time_frame,total_time_frame;
    CGRect fav_btn_frame;
    CGRect rate_btn_frame,rate_view_frame;
    CGRect rateBg_btn_frame;
    CGRect size_btn_frame;
    CGRect subtitle_frame;
    CGRect note_frame;
    CGRect volume_frame;
    CGRect schedule_frame;
    CGRect volume_view_frame,volume_slider_frame,volume_btn_frame;
    //问题标题和问题详细
    CGRect questionTitle_frame;
    CGRect question_frame;
    
    CGFloat height = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_HEIGHT:SCREEN_WIDTH;
    CGFloat width = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_WIDTH:SCREEN_HEIGHT;
    
    if (isPad) {
        //三大
        question_view_frame = RECT(0, 0, height, width);
        top_view_frame = RECT(0, 0, height, 97);
        bottom_view_frame = RECT(0, width-97, height, 97);
        main_view_frame = RECT(0, 97, height, width-194);
        //提问问题
        close_frame = RECT(0, 15, 110, 70);
        finish_frame = RECT(height-110, 15, 110, 70);
        questionTitle_frame = CGRectMake(100, 60, 400, 30);
        question_frame = CGRectMake(100, 100, 400, 200);
        
        //顶部的
        back_frame = RECT(0, 15, 110, 70);
        
        title_frame = RECT(130, 25, height-80-150, 50);
        mulu_frame = RECT(50, 25, 50, 50);
        shu_frame = RECT(110, 25, 10, 50);
        
        question_btn_frame = RECT(height-195, 30, 90, 37);
        quality_btn_frame = RECT(height-105, 30, 90, 37);
        quality_view_frame = RECT(height-105, 5, 90, 120);
        
        //底部的
        play_btn_frame = RECT(height/2-45, 10, 90, 90);
        pass_btn_frame = RECT(height/2-135, 10, 90, 90);
        next_ntm_frame = RECT(height/2+45, 10, 90, 90);
        progress_slider_frame = RECT(0, -16, height, 35);
        current_time_frame = RECT(20, 40, 150, 20);
        total_time_frame = RECT(15, 30, 100, 20);
        
        fav_btn_frame = RECT(height-175, 42, 20, 20);
        rate_btn_frame = RECT(height-105, 30, 90, 37);
        rate_view_frame = RECT(height-105,97 + main_view_frame.size.height-200-10, 90, 200+10);
        
        //        top_view_frame = RECT(0, 0, height, 97);
        //        bottom_view_frame = RECT(0, width-97, height, 97);
        //        main_view_frame = RECT(0, 97, height, width-194);
        
        size_btn_frame = RECT(height-60, 40, 33, 33);
        
        subtitle_frame = RECT(10, width-180-30, height-20, 30);
        
        note_frame = RECT(height/2-75, width/2-30, 150, 60);
        volume_frame = RECT(height/2-200, width/2+50, 96, 116);
        schedule_frame = RECT(height/2+104, width/2+50, 96, 116);
        
        volume_view_frame = CGRectMake(-8, width/2-(width-120*2)/2, 68, width-97*2-120*2);
        volume_slider_frame = CGRectMake(30-(width-97*2-120*2-60)/2+8, (width-97*2-120*2-60)/2, width-97*2-120*2-60, 20);
        volume_btn_frame = CGRectMake(10+8, width-97*2-120*2-40, 40, 30);
        //        if (IsIOS8) {
        //            //三大
        //            top_view_frame = RECT(0, 0, width, 97);
        //            bottom_view_frame = RECT(0, height-97, width, 97);
        //            main_view_frame = RECT(0, 80, width, height-180);
        //            //顶部的
        //            back_frame = RECT(0, 5, 70, 70);
        //
        //            title_frame = RECT(70, 10, width-80-150, 50);
        //
        //            quality_btn_frame = RECT(width-105, 38, 90, 37);
        //            quality_view_frame = RECT(width-105, 5, 90, 120);
        //
        //            //底部的
        //            play_btn_frame = RECT(10, 10, 90, 90);
        //            progress_slider_frame = RECT(120, 15, width-120-120-20, 35);
        //            current_time_frame = RECT(120, 55, 150, 20);
        //            total_time_frame = RECT(135, 30, 100, 20);
        //
        //            rate_btn_frame = RECT(width-105, 45, 90, 37);
        //            size_btn_frame = RECT(width-60, 40, 33, 33);
        //
        //            subtitle_frame = RECT(10, height-180-30, width-20, 30);
        //
        //            note_frame = RECT(width/2-75, height/2-30, 150, 60);
        //            volume_frame = RECT(width/2-200, height/2+50, 96, 116);
        //            schedule_frame = RECT(width/2+104, height/2+50, 96, 116);
        //        }
    }else{
        //三大
        question_view_frame = RECT(0, 0, height, width);
        top_view_frame = RECT(0, 0, height, 53);
        bottom_view_frame = RECT(0, width-50, height, 52);
        main_view_frame = RECT(0, 55, height, width-105);
        //提问问题
        close_frame = RECT(0, 15, 90, 50);
        finish_frame = RECT(height-90, 15, 90, 50);
        questionTitle_frame = CGRectMake(100, 60, 400, 30);
        question_frame = CGRectMake(100, 100, 400, 200);
        
        //顶部的
        back_frame = RECT(0, 5, 90, 50);
        
        title_frame = RECT(90, 10, height-60-100-10, 40);
        mulu_frame = RECT(30, 10, 40, 40);
        shu_frame = RECT(75, 10, 10, 40);
        
        question_btn_frame = RECT(height-116, 16, 50, 27);
        quality_btn_frame = RECT(height-56, 16, 50, 27);
        quality_view_frame = RECT(height-56, 2, 50, 80);
        
        //底部的
        play_btn_frame = RECT(height/2-27.5, 1, 55, 55);
        pass_btn_frame = RECT(height/2-82.5, 1, 55, 55);
        next_ntm_frame = RECT(height/2+27.5, 1, 55, 55);
        progress_slider_frame = RECT(-2, -10, height+4, 15);
        current_time_frame = RECT(15, 16, 150, 20);
        total_time_frame = RECT(15, 26, 100, 20);
        
        fav_btn_frame = RECT(height-96, 17, 20, 20);
        rate_btn_frame = RECT(height-56, 6, 50, 44);
        rateBg_btn_frame = RECT(height-56, 14, 50, 27);
        
        rate_view_frame = RECT(height-56,width-50 - 120, 50, 110+10);
        //        top_view_frame = RECT(0, 0, height, 97);
        //        bottom_view_frame = RECT(0, width-97, height, 97);
        //        main_view_frame = RECT(0, 97, height, width-194);
        
        size_btn_frame = RECT(height-40, 20, 25, 25);
        
        subtitle_frame = RECT(10, width-110-30, height-20, 30);
        
        note_frame = RECT(height/2-75, width/2-30, 150, 60);
        volume_frame = RECT(height/2-150, width/2+30, 48, 58);
        schedule_frame = RECT(height/2+102, width/2+30, 48, 58);
        
        volume_view_frame = CGRectMake(-8, (width-(width-20*2))/2, 50, width-55*2-20*2);
        volume_slider_frame = CGRectMake(32-(width-55*2-20*2-30)/2, (width-55*2-20*2-30)/2, width-55*2-20*2-40, 20);
        volume_btn_frame = CGRectMake(10, width-55*2-20*2-30, 40, 30);
        //        if (IsIOS8) {
        //            //三大
        //            top_view_frame = RECT(0, 0, width, 55);
        //            bottom_view_frame = RECT(0, height-55, width, 55);
        //            main_view_frame = RECT(0, 50, width, height-110);
        //            //顶部的
        //            back_frame = RECT(-5, 5, 50, 50);
        //
        //            title_frame = RECT(60, 10, width-60-100-10, 40);
        //
        //            quality_btn_frame = RECT(width-56, 20, 50, 27);
        //            quality_view_frame = RECT(width-56, 2, 50, 80);
        //
        //            //底部的
        //            play_btn_frame = RECT(10, 10, 35, 35);
        //            progress_slider_frame = RECT(60, 10, width-60-60-10, 15);
        //            current_time_frame = RECT(60, 30, 150, 20);
        //            total_time_frame = RECT(135, 30, 100, 20);
        //
        //            rate_btn_frame = RECT(width-56, 14, 50, 27);
        //            size_btn_frame = RECT(width-40, 20, 25, 25);
        //
        //            subtitle_frame = RECT(10, height-110-30, width-20, 30);
        //
        //            note_frame = RECT(width/2-75, height/2-30, 150, 60);
        //            volume_frame = RECT(width/2-150, height/2+30, 48, 58);
        //            schedule_frame = RECT(width/2+102, height/2+30, 48, 58);
        //        }
    }
    
    self.questionTitleTextFiled = [[UITextField alloc]init];
    self.questionTextView = [[UITextView alloc]init];
    self.questionTitleTextFiled.backgroundColor = [UIColor whiteColor];
    self.questionTextView.backgroundColor = [UIColor whiteColor];
    
    self.questionView.frame = question_view_frame;
    self.topView.frame = top_view_frame;
    self.bottomView.frame = bottom_view_frame;
    self.mainView.frame = main_view_frame;
    self.gestureView.frame = main_view_frame;
    
    self.closeBtn.frame = close_frame;
    self.finishBtn.frame = finish_frame;
    self.questionTextView.frame = question_frame;
    self.questionTitleTextFiled.frame = questionTitle_frame;
    
    self.backBtn.frame = back_frame;
    self.videoTitle.frame = title_frame;
    self.mulu.frame = mulu_frame;
    self.shu.frame = shu_frame;
    self.questionBtn.frame = question_btn_frame;
    self.qualityBtn.frame = quality_btn_frame;
    //    self.qualityView.frame = quality_view_frame;
    
    self.playBtn.frame = play_btn_frame;
    self.passBtn.frame = pass_btn_frame;
    self.nextBtn.frame = next_ntm_frame;
    self.progressSlider.frame = progress_slider_frame;
    self.currentProgressTime.frame = current_time_frame;
    self.videoTotalTime.frame = total_time_frame;
    
    self.favoriteBtn.frame = fav_btn_frame;
    
    self.videoRate.frame = rate_btn_frame;
    self.videoRateBg.frame = rateBg_btn_frame;
    self.rateView.frame = rate_view_frame;
    
    
    
    
    self.noteLabel.frame = note_frame;
    self.volume.frame = volume_frame;
    self.schedule.frame= schedule_frame;
    
    volumeView.frame = volume_view_frame;
    self.volumeSlider.frame = volume_slider_frame;
    self.volumeBtn.frame = volume_btn_frame;
    
    
    /**
     *  详细属性
     */
    
    //提问问题
    [self.closeBtn setTitle:@"关闭" forState:UIControlStateNormal];
    [self.closeBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.finishBtn setTitle:@"提交" forState:UIControlStateNormal];
    [self.finishBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    
    self.questionTitleTextFiled.textColor = [UIColor blackColor];
    self.questionTitleTextFiled.placeholder = @"标题";
    self.questionTitleTextFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.questionTextView.textColor = [UIColor blackColor];
    
    self.questionTextView.secureTextEntry = YES;
    
    if (isPad) {
        self.questionTitleTextFiled.font = FONT_SYS_BIG;
    }
    
    self.questionView.backgroundColor = [UIColor colorWithRed:250 green:250 blue:250 alpha:0.8];
    self.questionView.hidden = YES;
    self.topView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    self.bottomView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    [self.backBtn setImage:[UIImage imageNamed:@"back1"] forState:UIControlStateNormal];
    self.backBtn.layer.borderColor = [UIColor clearColor].CGColor;
    self.backBtn.layer.cornerRadius = 8;
    self.backBtn.layer.borderWidth = 2;
    [self.backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 50)];
    self.videoTitle.textColor = [UIColor whiteColor];
    self.videoTitle.textAlignment = NSTextAlignmentLeft;
    self.videoTitle.backgroundColor=[UIColor clearColor];
    self.shu.textColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1];
    self.shu.text = @"|";
    self.mulu.text = @"目录";
    self.mulu.textColor = [UIColor whiteColor];
    
    [self.questionBtn setTitle:@"提问" forState:UIControlStateNormal];
    self.questionBtn.titleLabel.font = FONT(15);
    self.questionBtn.backgroundColor=[UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:0.1];
    self.questionBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.questionBtn.layer.borderWidth = 1;
    self.questionBtn.layer.cornerRadius = 3;
    if (isPad) {
        self.questionBtn.titleLabel.font = FONT_BOLD_BIG;
    }
    
    [self.qualityBtn setTitle:@"清晰" forState:UIControlStateNormal];
    self.qualityBtn.titleLabel.font = FONT(15);
    self.qualityBtn.backgroundColor=[UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:0.1];
    self.qualityBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.qualityBtn.layer.borderWidth = 1;
    self.qualityBtn.layer.cornerRadius = 3;
    if (isPad) {
        self.qualityBtn.titleLabel.font = FONT_BOLD_BIG;
    }
    //    self.qualityView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    //    self.qualityView.backgroundColor = [UIColor redColor];
    //        self.qualityView.hidden = YES;
    //    self.qualityView.layer.cornerRadius = 3;
    
    [self.favoriteBtn setImage:[UIImage imageNamed:@"heart_white"] forState:UIControlStateNormal];
    [self.favoriteBtn setImage:[UIImage imageNamed:@"heart_red"] forState:UIControlStateSelected];
    
    [self.videoRate setTitle:@"1.0X" forState:UIControlStateNormal];
    if (isPad) {
        self.videoRate.layer.cornerRadius = 3;
    }
    self.rateView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    self.rateView.hidden = YES;
    self.rateView.layer.cornerRadius = 3;
    
    self.videoRateBg.layer.cornerRadius = 3;
    [self.videoRate setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    if (isPad) {
        
    }else{
        self.videoRate.titleLabel.font = FONT_SYS_NORMAL;
    }
    self.videoRate.backgroundColor = [UIColor clearColor];
    if (isPad) {
        self.videoRate.layer.borderWidth = 1;
        self.videoRate.layer.borderColor = [UIColor lightGrayColor].CGColor;
    }
    self.videoRateBg.layer.borderWidth = 1;
    self.videoRateBg.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    self.currentProgressTime.text = @"00:00/00:00";
    self.currentProgressTime.textColor = [UIColor whiteColor];
    self.currentProgressTime.font = [UIFont systemFontOfSize:15];
    self.currentProgressTime.backgroundColor=[UIColor clearColor];
    self.videoTotalTime.textColor = [UIColor whiteColor];
    self.videoTotalTime.backgroundColor=[UIColor clearColor];
    
    self.progressSlider.maximumValue = 1.0;
    self.progressSlider.minimumValue = 0.0;
    UIImage *leftImg =
    [[UIImage imageNamed:@"leftSlider5"]stretchableImageWithLeftCapWidth:1 topCapHeight:0];
    UIImage *rightImg =
    [[UIImage imageNamed:@"rightSlider5"]stretchableImageWithLeftCapWidth:1 topCapHeight:0];
    [self.progressSlider setMinimumTrackImage:leftImg forState:UIControlStateNormal];
    [self.progressSlider setMaximumTrackImage:rightImg forState:UIControlStateNormal];
    if (!isPad) {
        [self.progressSlider setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.progressSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }else{
        [self.progressSlider setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.progressSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }
    
    [self.passBtn setImage:[UIImage imageNamed:@"ic_retreat_media"] forState:UIControlStateNormal];
    [self.nextBtn setImage:[UIImage imageNamed:@"ic_next_play"] forState:UIControlStateNormal];
    
    self.noteLabel.textColor = [UIColor whiteColor];
    self.noteLabel.font = FONT_SYS_NORMAL;
    self.noteLabel.hidden = NO;
    self.noteLabel.text = @"加载中...";
    self.noteLabel.backgroundColor=[UIColor clearColor];
    self.noteLabel.textAlignment = NSTextAlignmentCenter;
    self.noteLabel.layer.borderWidth = 10;
    self.noteLabel.layer.borderColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0].CGColor;
    self.noteLabel.layer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4].CGColor;
    self.noteLabel.layer.cornerRadius = 5.0f;
    //阴影
    self.noteLabel.layer.shadowColor = [UIColor blackColor].CGColor;
    self.noteLabel.layer.shadowOffset = CGSizeMake(0, 3);
    self.noteLabel.layer.shadowOpacity = 1;
    self.noteLabel.layer.shadowRadius = 5;
    
    self.volume.image=[UIImage imageNamed:@"player_sound"];
    self.schedule.image=[UIImage imageNamed:@"player_progress"];
    
    if (isPad) {
        //
        self.backBtn.titleLabel.font = FONT_BOLD(14);
        self.videoTitle.font = FONT_SYS_BIG;
        self.mulu.font = FONT_SYS_BIG;
    }else{
        self.backBtn.titleLabel.font = FONT_BOLD(16);
        self.videoTitle.font = FONT(16);
        self.mulu.font = FONT_SYS(16);
    }
    
    self.volumeSlider.minimumValue = 0.0;
    self.volumeSlider.maximumValue = 1.0;
    self.volumeSlider.transform = CGAffineTransformMakeRotation(M_PI*-0.5);
    self.volumeSlider.minimumTrackTintColor = [UIColor orangeColor];
    if (!isPad) {
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }else{
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton"] forState:UIControlStateNormal];
        [self.volumeSlider setThumbImage:[UIImage imageNamed:@"player_redbutton_down"] forState:UIControlStateHighlighted];
    }
    //    [self.volumeSlider setMinimumTrackImage:leftImg forState:UIControlStateNormal];
    //    [self.volumeSlider setMaximumTrackImage:rightImg forState:UIControlStateNormal];
    volumeView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    volumeView.layer.cornerRadius = 5;
    [self.volumeBtn setImage:[UIImage imageNamed:@"player_volume_middle"] forState:UIControlStateNormal];
    [self.volumeBtn setImage:[UIImage imageNamed:@"player_volume_zero"] forState:UIControlStateSelected];
    [self.volumeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.volumeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    self.volumeBtn.titleLabel.font = FONT_SYS_NORMAL;
    
    /**
     *  添加控件
     */
    [volumeView addSubview:self.volumeSlider];
    [volumeView addSubview:self.volumeBtn];
    
    [self.questionView addSubview:self.closeBtn];
    [self.questionView addSubview:self.finishBtn];
    
    [self.topView addSubview:self.backBtn];
    [self.topView addSubview:self.videoTitle];
    [self.topView addSubview:self.mulu];
    [self.topView addSubview:self.shu];
    [self.topView addSubview:self.backBtn];
    
    [self.topView addSubview:self.questionBtn];
    [self.topView addSubview:self.qualityBtn];
    
    
    //    self.mainView.userInteractionEnabled = YES;
    //    [self.mainView addSubview:self.qualityView];
    [self.mainView addSubview:self.subtitleLabel];
    [self.mainView addSubview:volumeView];
    [self addSubview:self.rateView];
    
    
    //    [self.bottomView addSubview:self.rateView];
    [self.bottomView addSubview:self.playBtn];
    [self.bottomView addSubview:self.passBtn];
    [self.bottomView addSubview:self.nextBtn];
    [self.bottomView addSubview:self.progressSlider];
    [self.bottomView addSubview:self.currentProgressTime];
    //    [self.bottomView addSubview:self.videoTotalTime];
    if (!isPad) {
        [self.bottomView addSubview:self.videoRateBg];
    }
    [self.bottomView addSubview:self.favoriteBtn];
    [self.bottomView addSubview:self.videoRate];
    
    
    [self addSubview:self.topView];
    [self addSubview:self.mainView];
    [self addSubview:self.bottomView];
    [self addSubview:self.noteLabel];
    [self addSubview:self.gestureView];
    [self addSubview:self.volume];
    [self addSubview:self.schedule];
    [self addSubview:self.questionView];
    [self.questionView addSubview:self.questionTitleTextFiled];
    [self.questionView addSubview:self.questionTextView];
    
    self.rateView.userInteractionEnabled = YES;
    
    
    self.ztyrateView = [[UIView alloc]initWithFrame:RECT(height, width - 99 * 2 + 20, 50, 120)];
    self.ztyrateView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    self.ztyrateView.hidden = NO;
    //        self.ztyrateView.backgroundColor = [UIColor redColor];
    [self addSubview:self.ztyrateView];
    
    for (int i = 0; i<4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(isPad?15:5, 4+i*((self.ztyrateView.frame.size.height-10)/4), self.ztyrateView.frame.size.width-(isPad?30:10), (self.ztyrateView.frame.size.height-10)/4-4);
        [btn setTitle:[NSString stringWithFormat:@"%.1fX",0.8+0.2*i] forState:UIControlStateNormal];
        if (i==3) {
            [btn setTitle:@"1.5X" forState:UIControlStateNormal];
        }
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        btn.titleLabel.font = FONT_SYS_NORMAL;
        btn.layer.cornerRadius = 3;
        btn.tag = i;
        if (i==1) {
            _currentBtn = btn;
            btn.backgroundColor = [UIColor lightGrayColor];
            [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        }
        [btn addTarget:self action:@selector(changeVideoRate2:) forControlEvents:UIControlEventTouchUpInside];
        [self.ztyrateView addSubview:btn];
    }
    
    self.ztyQualityView = [[UIView alloc] initWithFrame:RECT(height-56, 64, 50, 80)];
    self.ztyQualityView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    self.ztyQualityView.hidden = YES;
    [self addSubview:self.ztyQualityView];
    
}



// 选择速率
-(void)changeVideoRate2:(UIButton *)btn{
    
    
    _currentBtn.backgroundColor = [UIColor clearColor];
    [_currentBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    
    _currentBtn = btn;
    
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor lightGrayColor];
    [self.delegate changeRata:btn.tag];
    
}

/**
 *  隐藏视图
 */
-(void)menuHiden{
    //FIXME:使用block的时候必须等动画执行完毕才能继续反应···这与block多线程不符啊，暂时未知，求可中断的话还是使用夹杂的方式
    //    [UIView animateWithDuration:1.0 animations:^{
    //        //
    //        self.noteLabel.hidden = YES;
    //        self.qualityView.hidden = YES;
    //        self.alpha = 0;
    //    }];
    self.gestureView.frame = self.frame;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.618];
    self.noteLabel.hidden = YES;
    //    self.qualityView.hidden = YES;
    self.ztyQualityView.hidden = YES;
    self.rateView.hidden = YES;
    self.topView.alpha = 0;
    self.mainView.alpha = 0;
    self.bottomView.alpha = 0;
    //    self.ztyQualityView.alpha = 0;
    
    //    self.ztyrateView.alpha = 0;
    [UIView animateWithDuration:0.4 animations:^{
        CGFloat height = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_HEIGHT:SCREEN_WIDTH;
        CGRect rect = self.ztyrateView.frame;
        //        if (rect.origin.x >= height - 56) {
        //            rect.origin.x -= 56;
        //        }else{
        //            rect.origin.x += 56;
        //        }
        rect.origin.x = height;
        self.ztyrateView.frame = rect;
        
    }];
    [UIView commitAnimations];
}
/**
 *  显示视图
 */
-(void)menuShow{
    CGRect frame = self.mainView.frame;
    frame.origin.x = 60;
    self.gestureView.frame = frame;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.0];
    self.hidden = NO;
    self.topView.alpha = 1;
    self.mainView.alpha = 1;
    self.bottomView.alpha = 1;
    [UIView commitAnimations];
}
/**
 *  视图移出
 */
-(void)menuOut{
    if (outflag) {
        return;
    }
    [UIView animateWithDuration:0.6 animations:^{
        //
        CGRect top_frame = self.topView.frame;
        CGRect bottom_frame = self.bottomView.frame;
        top_frame.origin.y = top_frame.origin.y-top_frame.size.height;
        bottom_frame.origin.y = bottom_frame.origin.y+bottom_frame.size.height;
        self.topView.frame = top_frame;
        self.bottomView.frame = bottom_frame;
        self.noteLabel.hidden = YES;
        //        self.qualityView.hidden = YES;
        self.ztyQualityView.hidden = YES;
        //        self.ztyrateView.hidden = YES;
        CGFloat height = SCREEN_HEIGHT>SCREEN_WIDTH?SCREEN_HEIGHT:SCREEN_WIDTH;
        CGRect rect = self.ztyrateView.frame;
        //        if (rect.origin.x >= height - 56) {
        //            rect.origin.x -= 56;
        //        }else{
        //            rect.origin.x += 56;
        //        }
        rect.origin.x = height;
        self.ztyrateView.frame = rect;
    }];
    outflag = YES;
}
/**
 *  视图移入
 */
-(void)menuIn{
    [UIView animateWithDuration:0.3 animations:^{
        //
        CGRect top_frame = self.topView.frame;
        CGRect bottom_frame = self.bottomView.frame;
        top_frame.origin.y = top_frame.origin.y+top_frame.size.height;
        bottom_frame.origin.y = bottom_frame.origin.y-bottom_frame.size.height;
        self.topView.frame = top_frame;
        self.bottomView.frame = bottom_frame;
    }];
    outflag = NO;
}

@end
